package com.yx.louti.config;

import com.yx.louti.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 姚天下
 * @version 1.0
 * @description: TODO
 * @date 2022/2/15 15:21
 */
public class WebAppConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;


    // SpringMVC 需要手动添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截
        {
            InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
            registration.addPathPatterns("/**");//所有路径都被拦截
            //添加不拦截路径
            registration.excludePathPatterns("/", "/user/login");
            registration.excludePathPatterns("/static/**");
            registration.excludePathPatterns("/vue-element-admin/**");
            registration.excludePathPatterns("/favicon.ico");
        }
    }

    //配置静态资源访问
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }
}
